//
//  HECartHeaderCell.m
//  HealthFamily
//
//  Created by 吴欧 on 2020/10/26.
//  Copyright © 2020 honglutec. All rights reserved.
//

#import "HECartHeaderCell.h"

@interface HECartHeaderCell ()

@property (nonatomic, strong) UIImageView *selectBtn;

@property (nonatomic, strong) UILabel *titleLb;
@property (nonatomic, strong) UIView *warp;
@end

@implementation HECartHeaderCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self=[super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self.backgroundColor = [UIColor clearColor];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self initUI];
    }
    return self;;
}

- (void)initUI {
    
    UIView *warp = [UIView new];
    _warp= warp;
    [self.contentView addSubview:warp];
    
    [warp mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).mas_offset(10);
        make.left.equalTo(self.contentView).mas_offset(15);
        make.right.equalTo(self.contentView).mas_offset(-15);
        make.bottom.equalTo(self.contentView).mas_offset(0);
    }];
    
    _selectBtn = [UIImageView new];
    _selectBtn.image = IMAGE_NAMED(@"check_box_unsel");
    _selectBtn.userInteractionEnabled = YES;
    [warp addSubview:_selectBtn];
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(selectGoodsClick)];
    [warp addGestureRecognizer:tap];
    
    _titleLb = [UILabel new];
    _titleLb.text = @"平台自营";
    _titleLb.font = DYBlodFont(16);
    [warp addSubview:_titleLb];
     
    [_selectBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(warp);
        make.left.equalTo(warp).mas_offset(10);
        make.width.height.mas_offset(25);
    }];
    
    [_titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(warp);
        make.left.equalTo(_selectBtn.mas_right).mas_offset(15);
        make.right.equalTo(warp).mas_offset(-15);
        make.bottom.equalTo(warp).mas_offset(-10);
    }];
    
    [warp hg_setCornerOnTopWithRadius:10.0f];

    warp.backgroundColor = [UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1.0];
    warp.layer.shadowColor = [UIColor colorWithRed:13/255.0 green:98/255.0 blue:218/255.0 alpha:0.08].CGColor;
    warp.layer.shadowOffset = CGSizeMake(0, 0);
    warp.layer.shadowOpacity = 1;
    warp.layer.shadowRadius = 6;
}


- (void)selectGoodsClick {
    
    _model.isChoose = !_model.isChoose;
    [self changeSelectBtnImage];
    
    if ([self.delegate respondsToSelector:@selector(carHeadSelect:withModel:)]) {
        [self.delegate carHeadSelect:self withModel:_model];
    }
}

- (void)changeSelectBtnImage {
    if (_model.isChoose) {
        _selectBtn.image = IMAGE_NAMED(@"check_box_sel");
    }else {
        _selectBtn.image = IMAGE_NAMED(@"check_box_unsel");
    }
}

- (void)setModel:(HEShopCarHeadModel *)model {
    _model = model;
    
    [self changeSelectBtnImage];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
